package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RefineOperBtn;
import com.tool.btn.goodbtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;
import org.come.Frame.MsgJframe;
import org.come.Frame.NewRefiningJframe;
import org.come.bean.QualityClBean;
import org.come.entity.Goodstable;
import org.come.mouslisten.RefinersMouslisten;
import org.come.mouslisten.WLLMouslisten;
import org.come.until.FormsManagement;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.UserMessUntil;

import javax.swing.*;
import java.awt.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class DianJpanel extends JPanel {
    public static FormsOnOffBtn offBtn;
    public double bili = 0.2;
    public QualityClBean clBean;
    public List<String> shuxing = new ArrayList<>();
    public List<Double> shuzhi = new ArrayList<>();
    String[] mes1 = {"加强混乱", "加强封印", "加强昏睡", "加强雷", "加强火", "加强鬼火", "强力克金", "加强克土", "加强克火", "加强克水", "加强克木", "加强风"};
    private JLabel[] labGoods = new JLabel[6];
    public static RefineOperBtn workshopBtn;// 炼化装备按钮
    public JLabel[] GoodsListLabel = new JLabel[24]; // 用来存放24个物品表格
    // 放置4个背包切换按钮
    private goodbtn[] btnrights;
    public BigDecimal money = new BigDecimal(1000000);// 消耗金钱
    public Goodstable[] goods = new Goodstable[6];
    public static RefineOperBtn operBtn3, operBtn2, operBtn1;

    public DianJpanel() {
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            this.setPreferredSize(new Dimension(470, 315));
            this.setLayout(null);
            this.setOpaque(false);

            for (int i = 0; i < 6; i++) {
                int row = i % 3;
                int col = i / 3;
                labGoods[i] = new JLabel();
                labGoods[i].addMouseListener(new RefinersMouslisten(this, 24 + i));
                labGoods[i].setBounds(250 + row * 67, 79 + col * 65, 54, 51);
                this.add(labGoods[i]);
            }
            // 关闭按钮事件
            offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 120);
            offBtn.setBounds(440, 10, 25, 25);
            this.add(offBtn);
            operBtn3 = new RefineOperBtn("skin/8100226/button/49.png", 1, UIUtils.COLOR_BTNTEXT,
                    UIUtils.TEXT_FONT, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 2, "再次炼化");
            operBtn3.setBounds(365, 29, 68, 17);
            this.add(operBtn3);
            operBtn1 = new RefineOperBtn("skin/8100226/button/18.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 0,
                    "保 留");
            operBtn1.setBounds(80, 275, 100, 26);
            this.add(operBtn1);
            // 替换新属性
            operBtn2 = new RefineOperBtn("skin/8100226/button/18.png", 1, UIUtils.COLOR_BTNPUTONG, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 1,
                    "替 换");
            operBtn2.setBounds(300, 275, 100, 26);
            this.add(operBtn2);
            for (int i = 0; i < 24; i++) {
                int row = i % 6;
                int col = i / 6;
                GoodsListLabel[i] = new JLabel();
                GoodsListLabel[i].addMouseListener(new RefinersMouslisten(this, i));
                GoodsListLabel[i].setBounds(218 + row * 51, 277 + col * 51, 49, 49);
                this.add(GoodsListLabel[i]);
            }
            // 背包四个页数的按钮
            btnrights = new goodbtn[6];
            for (int i = 0; i < btnrights.length; i++) {
                btnrights[i] = new goodbtn("skin/8100226/button/40-" + (i + 1) + ".png", 0, this, i);
                btnrights[i].setBounds(524, 284 + i * 35, 39, 31);
                this.add(btnrights[i]);
            }
            teji[0] = new JLabel();
            teji[0].setBounds(250, 200, 100, 28);
            teji[0].setVisible(false);
            teji[0].addMouseListener(new WLLMouslisten(100));
            teji[0].setFont(UIUtils.TEXT_HURT1);
            add(teji[0]);
            teji[1] = new JLabel();
            teji[1].setBounds(40, 200, 100, 28);
            teji[1].setVisible(false);
            teji[1].addMouseListener(new WLLMouslisten(101));
            teji[1].setFont(UIUtils.TEXT_HURT1);
            add(teji[1]);
        } else {
            this.setPreferredSize(new Dimension(470, 326));
            this.setLayout(null);
            this.setOpaque(false);

            for (int i = 0; i < 6; i++) {
                int row = i % 3;
                int col = i / 3;
                labGoods[i] = new JLabel();
                labGoods[i].addMouseListener(new RefinersMouslisten(this, 24 + i));
                labGoods[i].setBounds(250 + row * 67, 79 + col * 65, 54, 51);
                this.add(labGoods[i]);
            }
            // 关闭按钮事件
            offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 120);
            offBtn.setBounds(440, 5, 23, 23);
            this.add(offBtn);
            operBtn3 = new RefineOperBtn("inkImg/hongmu/a7.png", 1, UIUtils.COLOR_BTNPUTONG2,
                    UIUtils.TEXT_FONT, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 2, "再次炼化");
            operBtn3.setBounds(365, 29, 68, 51);
            this.add(operBtn3);
            operBtn1 = new RefineOperBtn("inkImg/hongmu/a2.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 0,
                    "保 留");
            operBtn1.setBounds(80, 240, 85, 72);
            this.add(operBtn1);
            // 替换新属性
            operBtn2 = new RefineOperBtn("inkImg/hongmu/a2.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel(), 1,
                    "替 换");
            operBtn2.setBounds(300, 240, 85, 72);
            this.add(operBtn2);
            for (int i = 0; i < 24; i++) {
                int row = i % 6;
                int col = i / 6;
                GoodsListLabel[i] = new JLabel();
                GoodsListLabel[i].addMouseListener(new RefinersMouslisten(this, i));
                GoodsListLabel[i].setBounds(218 + row * 51, 277 + col * 51, 49, 49);
                this.add(GoodsListLabel[i]);
            }
            // 背包四个页数的按钮
            btnrights = new goodbtn[6];
            for (int i = 0; i < btnrights.length; i++) {
                btnrights[i] = new goodbtn("inkImg/newbutton/C0" + (i + 1) + ".png", 0, this, i);
                btnrights[i].setBounds(524, 284 + i * 35, 39, 31);
                this.add(btnrights[i]);
            }
            teji[0] = new JLabel();
            teji[0].setBounds(250, 200, 100, 28);
            teji[0].setVisible(false);
            teji[0].addMouseListener(new WLLMouslisten(100));
            teji[0].setFont(UIUtils.TEXT_FONT);
            add(teji[0]);
            teji[1] = new JLabel();
            teji[1].setBounds(40, 200, 100, 28);
            teji[1].setVisible(false);
            teji[1].addMouseListener(new WLLMouslisten(101));
            teji[1].setFont(UIUtils.TEXT_FONT);
            add(teji[1]);
        }
    }

    static ImageIcon icon;
    ImageIcon icon1 = new ImageIcon("inkImg/old/background/S67.png");
    ImageIcon icon2 = new ImageIcon("inkImg/old/background/S154.png");
    private boolean p = true;
    private boolean zuo = false;
    private boolean you = false;
    static Random rand = new Random();

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        String style = MyIsif.getStyle();
        if ("水墨UI".equals(style)) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/old/background/点翠1.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 470, 315, this);
            g.setFont(UIUtils.nameFont);
            g.setColor(Color.white);
            g.drawString("原点翠属性", 55, 70);
            g.drawString("新点翠属性", 265, 70);
            if (isP()) {
                g.setColor(Color.black);
                if (isZuo()) {
                    g.drawString("总点翠值", 40, 135);
                    g.drawString("2", 170, 135);
                    g.drawImage(icon1.getImage(), 35, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 35, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 35, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 35, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(0), 45, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(0)), 35 + 140, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(1), 45, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(1)), 35 + 140, 175 + 18);
                    if (teji2 != 0) {
                        g.setColor(Color.GREEN);
                        g.drawImage(icon1.getImage(), 35, 200, (191), 28, this);
                        g.drawString("特技", 175, 175 + 42);
                        //  g.drawString(teji[0].getText(),250,175+42);
                        // g.drawImage(icon1.getImage(), 245, 230,  (191), 28, this);
                    }
                }
                if (isYou()) {
                    g.setFont(UIUtils.nameFont);
                    g.setColor(Color.black);
                    g.drawString("总点翠值", 40 + 210, 135);
                    g.drawString("2", 170 + 210 + 20, 135);
                    g.drawImage(icon1.getImage(), 245, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 245, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 245, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 245, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(2), 145 + 100, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(2)), 165 + 220, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(3), 145 + 100, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(3)), 165 + 220, 175 + 18);
                    if (teji1 != 0) {
                        g.setColor(Color.GREEN);
                        g.drawImage(icon1.getImage(), 245, 200, (191), 28, this);
                        g.drawString("特技", 165 + 220, 175 + 42);
                        //  g.drawString(teji[0].getText(),250,175+42);
                        // g.drawImage(icon1.getImage(), 245, 230,  (191), 28, this);
                    }
                }
            }
        } else {
            if (icon == null) {
                icon = new ImageIcon("inkImg/hongmu/点翠红木.png");
            }
            g.drawImage(icon.getImage(), 0, 0, 470, 315, this);
            g.setFont(UIUtils.nameFont);
            g.setColor(Color.orange);
            g.drawString("原点翠属性", 55, 70);
            g.drawString("新点翠属性", 265, 70);
            if (isP()) {
                g.setColor(Color.orange);
                if (isZuo()) {
                    g.drawString("总点翠值", 40, 135);
                    g.drawString("2", 170, 135);
                    g.drawImage(icon1.getImage(), 35, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 35, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 35, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 35, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(0), 45, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(0)), 35 + 140, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(1), 45, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(1)), 35 + 140, 175 + 18);
                    if (teji2 != 0) {
                        g.setColor(Color.GREEN);
                        g.drawImage(icon1.getImage(), 35, 200, (191), 28, this);
                        g.drawString("特技", 175, 175 + 42);
                        //  g.drawString(teji[0].getText(),250,175+42);
                        // g.drawImage(icon1.getImage(), 245, 230,  (191), 28, this);
                    }
                }
                if (isYou()) {
                    g.setFont(UIUtils.nameFont);
                    g.setColor(Color.orange);
                    g.drawString("总点翠值", 40 + 210, 135);
                    g.drawString("2", 170 + 210 + 20, 135);
                    g.drawImage(icon1.getImage(), 245, 140, (191), 28, this);
                    g.drawImage(icon1.getImage(), 245, 170, (191), 28, this);
                    g.drawImage(icon2.getImage(), 245, 140, (int) (133 * getBili()), 28, this);
                    g.drawImage(icon2.getImage(), 245, 170, (int) (133 * getBili()), 28, this);
                    g.setFont(UIUtils.TEXT_FONT2);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(2), 145 + 100, 140 + 20);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(2)), 165 + 220, 140 + 18);
                    g.setColor(Color.green);
                    g.drawString(getShuxing().get(3), 145 + 100, 175 + 15);
                    g.setColor(Color.white);
                    g.drawString(String.valueOf(getShuzhi().get(3)), 165 + 220, 175 + 18);
                    if (teji1 != 0) {
                        g.setColor(Color.GREEN);
                        g.drawImage(icon1.getImage(), 245, 200, (191), 28, this);
                        g.drawString("特技", 165 + 220, 175 + 42);
                        //  g.drawString(teji[0].getText(),250,175+42);
                        // g.drawImage(icon1.getImage(), 245, 230,  (191), 28, this);
                    }
                }
            }
        }
    }

    public static RefineOperBtn getOperBtn1() {
        return operBtn1;
    }

    public static void setOperBtn1(RefineOperBtn operBtn1) {
        DianJpanel.operBtn1 = operBtn1;
    }

    public static FormsOnOffBtn getOffBtn() {
        return offBtn;
    }

    public static void setOffBtn(FormsOnOffBtn offBtn) {
        DianJpanel.offBtn = offBtn;
    }

    public static RefineOperBtn getWorkshopBtn() {
        return workshopBtn;
    }

    public static void setWorkshopBtn(RefineOperBtn workshopBtn) {
        DianJpanel.workshopBtn = workshopBtn;
    }

    public static RefineOperBtn getOperBtn2() {
        return operBtn2;
    }

    public static void setOperBtn2(RefineOperBtn operBtn2) {
        DianJpanel.operBtn2 = operBtn2;
    }

    public static RefineOperBtn getOperBtn3() {
        return operBtn3;
    }

    public static void setOperBtn3(RefineOperBtn operBtn3) {
        DianJpanel.operBtn3 = operBtn3;
    }

    public void ew(QualityClBean clBean) {
        setP(true);

        String[] mes1 = clBean.getNewAttr().split("&");
        shuxing.set(2, mes1[1].split("=")[0]);
        shuzhi.set(2, Double.valueOf(mes1[1].split("=")[1]));
        shuxing.set(3, mes1[2].split("=")[0]);
        shuzhi.set(3, Double.valueOf(mes1[2].split("=")[1]));
        setYou(true);
        this.clBean = clBean;
        if (mes1.length == 5) {
            teji1 = Integer.parseInt(mes1[4].split("=")[1]);
            teji[0].setVisible(true);
            teji[0].setText(UserMessUntil.getSkillId(String.valueOf(teji1)).getSkillname());
            teji[0].setForeground(Color.green);
            // part= SpriteFactory.createPart("12008", -2, 1, null);
            MsgJframe.getJframe().getJapnel().texiao("悟技");

        } else {
            teji1 = 0;
            teji[0].setVisible(false);
        }

    }

    public static int teji1 = 0;
    public static int teji2 = 0;

    public void TH(QualityClBean clBean) {
        Goodstable good = GoodsListFromServerUntil.getRgid(clBean.getRgid());
        assert good != null;
        String[] value = good.getValue().split("\\|");
        List<String> value1 = new ArrayList<>();
        for (String s : value) {
            if (!s.startsWith("点翠属性") && !s.startsWith("炼化属性&特技")) {
                value1.add(s);
            }
        }
        value1.removeIf(bb -> "".equals(bb));
        StringBuilder mes = null;
        for (String vv : value1) {
            if (vv.startsWith("培养")) {

                assert mes != null;
                mes.append("|");
                mes.append(clBean.getNewAttr());
                mes.append("|");
            }
            if (mes == null) {
                mes = new StringBuilder(vv);
            } else {
                mes.append("|").append(vv);
            }
        }
        assert mes != null;
        good.setValue(mes.toString());
        shuxing.set(0, shuxing.get(2));
        shuxing.set(1, shuxing.get(3));
        shuzhi.set(0, shuzhi.get(2));
        shuzhi.set(1, shuzhi.get(3));
        this.clBean = null;
        setYou(false);
        setZuo(true);
        if (clBean.getNewAttr().split("&").length == 5) {
            teji2 = Integer.parseInt(clBean.getNewAttr().split("&")[4].split("=")[1]);
            teji[1].setVisible(true);
            teji[1].setText(UserMessUntil.getSkillId(String.valueOf(teji2)).getSkillname());
            teji[1].setForeground(Color.green);
            teji[0].setVisible(false);
        } else {
            teji2 = 0;
            teji[1].setVisible(false);
        }
    }

    public JLabel[] teji = new JLabel[2];

    public static double dianchizhi() {

        /*int k=0;
        int l=5;
        k=rand.nextInt(10);*/
        return 1;
    }

    public double getBili() {

        return bili;
    }


    public void setBili(double bili) {
        this.bili = bili;
    }

    public List<String> getShuxing() {
      /*  if (shuxing.size()!=0)
            shuxing.clear();
        for (int i=0;i<=3;i++){
            shuxing.add(mes1[rand.nextInt(12)]);
        }*/
        return shuxing;
    }

    public void setShuxing(List<String> shuxing) {
        this.shuxing = shuxing;
    }

    public List<Double> getShuzhi() {
       /* shuzhi.clear();
        for (int i=0;i<=3;i++){
            shuzhi.add(rand.nextInt(10)/10.0);
        }*/
        return shuzhi;
    }

    public void setShuzhi(List<Double> shuzhi) {

        this.shuzhi = shuzhi;
    }

    /**
     * 显示
     */
    public void show(String value, int leixing, boolean is) {
        p = true;
        setZuo(false);
        setYou(false);
        shuzhi.clear();
        shuxing.clear();
        shuxing.add("1");
        shuzhi.add(1.0);
        shuxing.add("2");
        shuzhi.add(3.0);
        shuxing.add("1");
        shuzhi.add(1.0);
        shuxing.add("2");
        shuzhi.add(3.0);
        if (value != null) {
            String[] mes1 = value.split("&");
            shuxing.set(0, mes1[1].split("=")[0]);
            shuzhi.set(0, Double.valueOf(mes1[1].split("=")[1]));
            shuxing.set(1, mes1[2].split("=")[0]);
            shuzhi.set(1, Double.valueOf(mes1[2].split("=")[1]));
            setZuo(true);
            if (mes1.length == 5) {
                teji2 = Integer.parseInt(mes1[4].split("=")[1]);
                teji[1].setVisible(true);
                teji[1].setText(UserMessUntil.getSkillId(String.valueOf(teji2)).getSkillname());
                teji[1].setForeground(Color.green);
                teji[0].setVisible(false);
            } else {
                teji2 = 0;
                teji[1].setVisible(false);

            }

        }
        NewRefiningJframe.getNewRefiningJframe().getRefiningJpanel().leixing = 0;
        FormsManagement.showForm(120);
    }

    public String[] getMes1() {
        return mes1;
    }

    public void setMes1(String[] mes1) {
        this.mes1 = mes1;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

    public ImageIcon getIcon2() {
        return icon2;
    }

    public void setIcon2(ImageIcon icon2) {
        this.icon2 = icon2;
    }

    public boolean isP() {
        return p;
    }

    public void setP(boolean p) {
        this.p = p;
    }

    public boolean isZuo() {
        return zuo;
    }

    public void setZuo(boolean zuo) {
        this.zuo = zuo;
    }

    public boolean isYou() {
        return you;
    }

    public void setYou(boolean you) {
        this.you = you;
    }

    public static Random getRand() {
        return rand;
    }

    public static void setRand(Random rand) {
        DianJpanel.rand = rand;
    }
}
